package cn.gwm.utils;

import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
 * java流工具
 * @author GW00283474
 */
public class StreamUtil {

    /**
     * 迭代器转化流
     * @param iterator
     * @param <T>
     * @return
     */
    public static <T> Stream<T> convertIterator(Iterator<T> iterator) {
        return StreamSupport.stream(((Iterable) () -> iterator).spliterator(), false);
    }

    /**
     * 迭代器转化为List
     * @param iterable
     * @param <T>
     * @return
     */
    public static <T> List<T> convertIterable(Iterable<T> iterable){
        return StreamSupport.stream(iterable.spliterator(),false).collect(Collectors.toList());
    }
}
